[Contribution] pyhealth.graph: Native knowledge graph support + GraphProcessor#853
Merged
jhnwu3 merged 4 commits intosunlabuiuc:masterfrom Feb 17, 2026
Merged
Conversation
added 4 commits
February 15, 2026 20:18
jhnwu3
approved these changes
Feb 17, 2026
Collaborator
jhnwu3
left a comment
There was a problem hiding this comment.
Okay this is clean, lgtm. We can iterate when we run into issues. Iirc we may need to test if litdata can properly serialize PyG objects, which iirc is just a class of 2-3 tensors, but let's work through this as we go along. I think you pretty much hit on the head exactly what I was thinking 😂 . Nice stuff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributor Information
Description
Adds native knowledge graph support to PyHealth via a new
pyhealth.graphmodule and aGraphProcessorinpyhealth.processors. This is foundational infrastructure enabling graph-based EHR models (GraphCare, G-BERT, KAME, etc.) to consume standard PyHealth datasets through the existing processor/schema pipeline.Builds on Patrick Jiang's earlier
BaseKGDatasetwork on thekg_embeddingbranch, updated for PyHealth 2.0's processor architecture.What's included:
pyhealth.graph.KnowledgeGraph— Core data structure for medical knowledge graphs:edge_index+edge_typetensorssubgraph()extraction viatorch_geometric.utils.k_hop_subgraphpyhealth.processors.GraphProcessor— Registered processor bridging EHR codes to graphs:Datasubgraphmax_nodespruning (seeds always kept)FeatureProcessorinterface:is_token(),schema(),dim(),spatial()Collation update — Added PyG
Databranch tocollate_fn_dict_with_padding:Dataobjects and batches viaBatch.from_data_list()torch-geometricis optional — gracefully skips when not installedUsage
Design decisions:
torch-geometricis an optional dependency — imported only when graph features are usedTimeImageProcessorfor registration and integrationFiles to Review
New files:
pyhealth/graph/__init__.py— module exportspyhealth/graph/knowledge_graph.py— KnowledgeGraph classpyhealth/processors/graph_processor.py— GraphProcessortests/core/test_knowledge_graph.py— 22 unit teststests/core/test_graph_processor.py— 19 unit testsdocs/api/graph.rst— graph module docsdocs/api/graph/pyhealth.graph.KnowledgeGraph.rst— KG API docsdocs/api/processors/pyhealth.processors.GraphProcessor.rst— processor docsEdited files:
pyhealth/processors/__init__.py— added GraphProcessor importpyhealth/datasets/utils.py— added PyG collation branchdocs/api/processors.rst— added to toctreedocs/index.rst— added graph sectionTesting
Next steps (separate PRs)